package com.credithc.signature.common.service;

import com.credithc.signature.common.constant.CacheConstant;
import com.credithc.signature.common.constant.ManagerConstant;
import com.credithc.signature.common.mapper.OfficialSealTemplateMapper;
import com.credithc.signature.common.po.OfficialSealTemplate;
import com.credithc.signature.common.utils.CacheUtil;
import com.credithc.signature.common.utils.ManagerBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * 描述：公章与模板中间服务<br/>
 * 作者：sunyang
 * 创建：2019/6/10 17:42
 * 版本：v1.0.0<br/>
 */
@Service
public class OfficialSealTemplateService {

    @Autowired
    private OfficialSealTemplateMapper officialSealTemplateMapper;

    public int insert(OfficialSealTemplate officialSealTemplate) {
        return officialSealTemplateMapper.insert(officialSealTemplate);
    }

    public int deleteByExample(OfficialSealTemplate officialSealTemplate) {
        Map<String, Object> paramsMap = ManagerBeanUtil.buildQueryParams(officialSealTemplate);
        return officialSealTemplateMapper.deleteByExample(paramsMap.get(ManagerConstant.EXAMPLE));
    }

    public List<OfficialSealTemplate> selectByExample(OfficialSealTemplate officialSealTemplate) {
        Map<String, Object> params = ManagerBeanUtil.buildQueryParams(officialSealTemplate);
        return officialSealTemplateMapper.selectByExample(params.get(ManagerConstant.EXAMPLE));
    }

    public int updateSealCodeByTempNoAndSealCode(OfficialSealTemplate officialSealTemplate, String sealCode) {
        return officialSealTemplateMapper.updateSealCodeByTempNoAndSealCode(officialSealTemplate, sealCode);
    }

    public List<OfficialSealTemplate> selectByTemplateNo(String templateNo) {
        List<OfficialSealTemplate> ofst = null;
        try {
            ofst = CacheUtil.getTemplateSealLoadingCache().get(CacheConstant.TEMPLATE_SEAL_PREFIX + templateNo);
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return ofst;
    }
}
